import * as Nexus from "@nexus/schema";
import { UserInputError } from "apollo-server-koa";
import AuthenticateService from "../../../service/authenticate";
import { Context } from "../../path/to/contextModule/contextModule";

// 拓展类型
export default Nexus.extendType({
  // 类型
  type: "Query",

  // 定义
  definition: (t) => {
    // 帖子
    t.field("adminInfo", {
      // 类型
      type: "AdminInfo",

      // 权限认证
      authorize: (_root, _args, ctx, info) => {
        return ctx.service.authenticate.authenticate(info);
      },
      // 解析
      resolve: async (_root, _args, ctx, _info) => {
        const { token, db } = ctx;
        const { adminId } = token.sub;
        return db.admin.findUnique({ where: { id: adminId } });
      },
    });
  },
});
